// auther by Zhaowenhe
// 2017/12/6
// 显示个人库存列表
var local="http://47.104.10.151";

var order_id1;
var order_id2;
var order_id3;
var order_id4;
var order_id5;
var order_id6;
var xmlHttp;
var keyId=getCookie('userId');
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return ""
}
var page=0;
var url=local+":8080/stock/getListByUserId/";
function creatxmlHTTP() {
    if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlHttp=new XMLHttpRequest();
    }else {
        // IE6, IE5 浏览器执行代码
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    return xmlHttp;
}
function getInvite() {
    var kid=getCookie('userId');
    var url = local+":8080/login/displayCompany_Code";
    var xmlHttp = creatxmlHTTPInvite();
    var txt = "";//用于存储拼接字符串；
    //获取数据
    //拼接字符
    txt = "user_Id=" + kid;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    function creatxmlHTTPInvite() {
        if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
            xmlHttp=new XMLHttpRequest();
        }else {
            // IE6, IE5 浏览器执行代码
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        return xmlHttp;
    }
    xmlHttp.onreadystatechange=function()
    {
        if (xmlHttp.readyState==4 && xmlHttp.status==200)
        {
            var result=xmlHttp.responseText;
            var json=eval("("+result+")");
            document.getElementById("invite_code").value=json.msg;
        }
    }
}

function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return ""
}
function SeachStock() {
    var xmlHttp = creatxmlHTTP();
    var txt = "";//用于存储拼接字符串；
    var url=local+":8080/stock/getListByUserId";
    //拼接字符?user_id=2&page=0
    txt = "user_id=" + keyId + "&page=" + page;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);


    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var result = xmlHttp.responseText;
            var json = eval("(" + result + ")");

            totalPages=json.data.totalPages;

            var input1 = document.getElementsByName("Bid1");
            if (json.data.content[0].tax_status == 0) {
                input1[8].value = "无税率";
            } else if(json.data.content[0].tax_status == 1){
                input1[8].value = "17%";
            }
            order_id1=json.data.content[0].keyId;
            input1[0].value = 1;
            input1[1].value = json.data.content[0].product_name;
            input1[2].value = json.data.content[0].model_code;
            input1[3].value = json.data.content[0].size;
            input1[4].value = json.data.content[0].brand;
            input1[5].value = json.data.content[0].sale_price;
            input1[6].value = json.data.content[0].inventory;
            input1[7].value = json.data.content[0].area_name;
            
            var input2 = document.getElementsByName("Bid2");
            if (json.data.content[1].tax_status == 0) {
                input2[8].value = "无税率";
            } else if(json.data.content[1].tax_status == 1){
                input2[8].value = "17%";
            }
            order_id2=json.data.content[1].keyId;
            input2[0].value = 1;
            input2[1].value = json.data.content[1].product_name;
            input2[2].value = json.data.content[1].model_code;
            input2[3].value = json.data.content[1].size;
            input2[4].value = json.data.content[1].brand;
            input2[5].value = json.data.content[1].sale_price;
            input2[6].value = json.data.content[1].inventory;
            input2[7].value = json.data.content[1].area_name;

            var input3 = document.getElementsByName("Bid3");
            if (json.data.content[2].tax_status == 0) {
                input3[8].value = "无税率";
            } else if(json.data.content[2].tax_status == 1){
                input3[8].value = "17%";
            }
            order_id3=json.data.content[2].keyId;
            input3[0].value = 1;
            input3[1].value = json.data.content[2].product_name;
            input3[2].value = json.data.content[2].model_code;
            input3[3].value = json.data.content[2].size;
            input3[4].value = json.data.content[2].brand;
            input3[5].value = json.data.content[2].sale_price;
            input3[6].value = json.data.content[2].inventory;
            input3[7].value = json.data.content[2].area_name;

            var input4 = document.getElementsByName("Bid4");
            if (json.data.content[3].tax_status == 0) {
                input4[8].value = "无税率";
            } else if(json.data.content[3].tax_status == 1){
                input4[8].value = "17%";
            }
            order_id4=json.data.content[3].keyId;
            input4[0].value = 1;
            input4[1].value = json.data.content[3].product_name;
            input4[2].value = json.data.content[3].model_code;
            input4[3].value = json.data.content[3].size;
            input4[4].value = json.data.content[3].brand;
            input4[5].value = json.data.content[3].sale_price;
            input4[6].value = json.data.content[3].inventory;
            input4[7].value = json.data.content[3].area_name;

            var input5 = document.getElementsByName("Bid5");
            if (json.data.content[4].tax_status == 0) {
                input5[8].value = "无税率";
            } else if(json.data.content[4].tax_status == 1){
                input5[8].value = "17%";
            }
            order_id5=json.data.content[4].keyId;
            input5[0].value = 1;
            input5[1].value = json.data.content[4].product_name;
            input5[2].value = json.data.content[4].model_code;
            input5[3].value = json.data.content[4].size;
            input5[4].value = json.data.content[4].brand;
            input5[5].value = json.data.content[4].sale_price;
            input5[6].value = json.data.content[4].inventory;
            input5[7].value = json.data.content[4].area_name;

            var input6 = document.getElementsByName("Bid6");
            if (json.data.content[5].tax_status == 0) {
                input6[8].value = "无税率";
            } else {if(json.data.content[5].tax_status == 1)
                input6[8].value = "17%";
            }
            order_id6=json.data.content[5].keyId;
            input6[0].value = 1;
            input6[1].value = json.data.content[5].product_name;
            input6[2].value = json.data.content[5].model_code;
            input6[3].value = json.data.content[5].size;
            input6[4].value = json.data.content[5].brand;
            input6[5].value = json.data.content[5].sale_price;
            input6[6].value = json.data.content[5].inventory;
            input6[7].value = json.data.content[5].area_name;


        }
    }

}






//通过鼠标点击事件创建HTTP请求
function confmFH1() {
    var xmlHttp = createXMLHttp();
    txt ="order_id="+order_id1;
    var url = local+":8080/stockorder/orderChangeTo2";//服务器URL
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    //传输结束
}

function confmFH2() {
    xmlHttp = createXMLHttp();
    txt ="order_id="+order_id2;
    var url = local+":8080/stockorder/orderChangeTo2";//服务器URL
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    //传输结束
}

function confmFH3() {
    xmlHttp = createXMLHttp();
    txt ="order_id="+order_id3;
    var url = local+":8080/stockorder/orderChangeTo2";//服务器URL
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    //传输结束
}

function confmFH4() {
    xmlHttp = createXMLHttp();
    txt ="order_id="+order_id4;
    alert(txt);
    var url = local+":8080/stockorder/orderChangeTo2";//服务器URL
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    //传输结束
}

function confmFH5() {
    xmlHttp = createXMLHttp();
    txt ="order_id="+order_id5;
    var url = local+":8080/stockorder/orderChangeTo2";//服务器URL
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    //传输结束
}

function confmFH6() {
    xmlHttp = createXMLHttp();
    txt ="order_id="+order_id6;
    var url = local+":8080/stockorder/orderChangeTo2";//服务器URL
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    //传输结束
}

//适配浏览器
//根据不同浏览器发送不同请求
function createXMLHttp() {
    //使用大部分浏览器
    var xmlHttp;
    if(window.XMLHttpRequest){
        xmlHttp=new XMLHttpRequest();
    }
    if(window.ActiveXObject){
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        if(!xmlHttp){
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
    }
    return xmlHttp;
}

function nextPage_bid() {
    page++;
    if(totalPages>page){
        SeachStock();
    }
    else alert("已经是最后一页");
}


function beforePage_bid() {
    page--;
    if(page>=0){
        SeachStock();
    }
    else alert("第一页");
}





$( document ).ready(function() {

    SeachStock();getInvite();

});